package dto

import (
	"tuowei.com/app/admin/models"
	"tuowei.com/common/dto"
)

type AddTeachingPoint struct {
	Name string `json:"name"`
}

type SysTeachingPointUpdateRequest struct {
	Id           int    `json:"id" binding:"required" json:"id"`
	Name         string `gorm:"type:varchar(64);comment:名字" json:"name"`
	Number       string `gorm:"type:varchar(64);comment:编号" json:"number"`
	ProvinceId   int    `gorm:"type:int(10);column:province_id;comment:省id" json:"province_id"`
	CityId       int    `gorm:"type:int(10);column:city_id;comment:市id" json:"city_id"`
	CountyId     int    `gorm:"type:int(10);column:county_id;comment:县id" json:"county_id"`
	DepartmentId int    `gorm:"type:int(10);column:department_id;comment:所属部门id" json:"department_id"`
	ControllerId []int  `gorm:"type:int(10);column:controller_id;comment:负责人userid" json:"controller_id"`
	EnrollmentId []int  `gorm:"type:int(10);column:enrollment_id;comment:招生老师userid" json:"enrollment_id"`
	Address      string `gorm:"type:varchar(64);column:address;comment:地址" json:"address"`
}

func (s *SysTeachingPointUpdateRequest) Generate(model *models.SysTeachingPoint) {
	model.Id = s.Id
	model.Name = s.Name
	model.ProvinceId = s.ProvinceId
	model.CityId = s.CityId
	model.CountyId = s.CountyId
	model.DepartmentId = s.DepartmentId
	model.Address = s.Address
	if len(s.ControllerId) > 0 {
		arr := make([]models.SysUser, 0)
		for _, v := range s.ControllerId {
			arr = append(arr, models.SysUser{UserId: v})
		}
		model.Controllers = &arr
	}
	if len(s.EnrollmentId) > 0 {
		arr := make([]models.SysUser, 0)
		for _, v := range s.EnrollmentId {
			arr = append(arr, models.SysUser{UserId: v})
		}
		model.Enrollments = &arr
	}
}

type SysTeachingAddPointRequest struct {
	Name         string `gorm:"type:varchar(64);comment:名字" json:"name"`
	Number       string `gorm:"type:varchar(64);comment:编号" json:"number"`
	ProvinceId   int    `gorm:"type:int(10);column:province_id;comment:省id" json:"province_id"`
	CityId       int    `gorm:"type:int(10);column:city_id;comment:市id" json:"city_id"`
	CountyId     int    `gorm:"type:int(10);column:county_id;comment:县id" json:"county_id"`
	DepartmentId int    `gorm:"type:int(10);column:department_id;comment:所属部门id" json:"department_id"`
	ControllerId []int  `gorm:"type:int(10);comment:负责人userid" json:"controller_id"`
	EnrollmentId []int  `gorm:"type:int(10);column:enrollment_id;comment:招生老师userid" json:"enrollment_id"`
	Address      string `gorm:"type:varchar(64);column:address;comment:地址" json:"address"`
}

type SysTeachingPointListRequest struct {
	dto.Pagination `search:"-"`
	Name           string `gorm:"type:varchar(64);comment:名字" json:"name" form:"name"`
}

func (s *SysTeachingAddPointRequest) Generate(model *models.SysTeachingPoint) {
	model.Name = s.Name
	model.ProvinceId = s.ProvinceId
	model.CityId = s.CityId
	model.CountyId = s.CountyId
	model.DepartmentId = s.DepartmentId
	model.Controllers = &[]models.SysUser{}
	model.Address = s.Address
	if len(s.ControllerId) > 0 {
		arr := make([]models.SysUser, 0)
		for _, v := range s.ControllerId {
			arr = append(arr, models.SysUser{UserId: v})
		}
		model.Controllers = &arr
	}
	if len(s.EnrollmentId) > 0 {
		arr := make([]models.SysUser, 0)
		for _, v := range s.EnrollmentId {
			arr = append(arr, models.SysUser{UserId: v})
		}
		model.Enrollments = &arr
	}
}

type SysTeachingPointDeleteRequest struct {
	Ids []int `json:"ids" form:"ids" binding:"required"`
}

type SysTeachingPointDetailRequest struct {
	Id int `uri:"id"`
}
